document.loading = false;

var html_url = "/html/ipad.html";

var ipad = navigator.userAgent.indexOf("(iPad;") > -1;
var width = ipad ? 2048 : 2532;
var height = ipad ? 1348 : 1998;
var zoom = window.innerWidth / width;
console.log("zoom = " + zoom);
var portrait = 0 === Math.abs(window.orientation);

$.ajax({
    url : html_url,
    success : function(response) {
        $("body").html(response);
        core.init();
    }
});

var core = {
  init : function() {
    $("#left").html(left.html);
    $("#right").html(right.html);
    $("body").css({ zoom : zoom });
    window.addEventListener("resize", this.resize, false);
    if (!ipad) {
      $("#wrapper").addClass("desktop");
    }
    if (ipad && portrait) {
      this.rotate();
    }
  },

  rotate : function() {
    zoom = window.innerWidth / width;
    if (!ipad) {
      $("body").css({ zoom : zoom });
    }
    /*
     var body = $("body");
     portrait = 0 == Math.abs(window.orientation);
     var rotate_css = "rotate(" + (portrait ? "90" : "0") + "deg)";
     body.css({ "-webkit-transform" : rotate_css });
     zoom = window.innerWidth / (portrait ? height : width);
     */
  },

  resize : function() {
    if (!ipad) {
      var wrapper = $("#wrapper");
      var width = wrapper.width() + parseInt(wrapper.css("padding-left")) + parseInt(wrapper.css("padding-right"));
      zoom = window.innerWidth / width;
      $("body").css("zoom", zoom);
    }
  }
};

// window.addEventListener(window.onorientationchange ? "orientationchange" : "resize", core.rotate, false);

var left = {
  html : "<div style='text-align: center'>Left</div>"
};

var right = {
  html : "<div style='text-align: center'>Right</div>"
};